﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WXY.Course.BLL;
using WXY.Course.Common.Authorization;
using WXY.Course.Model;

namespace WXY.Course.Web.Areas.Admin.Models
{
    public class AdminContext
    {
        public static bool IsLogin
        {
            get
            {
                string userName = DefaultAuthorization.GetUser();
                return !string.IsNullOrEmpty(userName);
            }
        }

        public static UserInfo GetCurrentUser()
        {
            string userName = DefaultAuthorization.GetUser();
            if (string.IsNullOrEmpty(userName))
            {
                return null;
            }
            return new AccountBLL().GetByName(userName);
        }

        public static void Login(UserInfo info)
        {
            DefaultAuthorization.SetAuthorized(info.Name);
        }

        public static void LogOut()
        {
            DefaultAuthorization.LogOut();
        }
    }
}